﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace adonet
{
    class Puller
    {
        public List<Member> Pull() {
            SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Q12013;Integrated Security=True");
            List<Member> members = new List<Member>();
            try
            {
                string query = "SELECT * FROM Members";
                SqlCommand command = new SqlCommand(query, cn);
                SqlDataAdapter ad = new SqlDataAdapter(command);
                DataSet ds = new DataSet();
                ad.Fill(ds);
                
                DataTable memberTable = ds.Tables[0];
                foreach (DataRow row in memberTable.Rows)
                {
                    Member member = new Member();
                    member.ID = Int32.Parse(row["ID"].ToString());
                    member.Name = row["Name"].ToString();
                    members.Add(member);
                }
                //Console.WriteLine(ds.GetXml());
                

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                cn.Close();
            }
            finally
            {
                cn.Close();
            }
            return members;
        }
    }
}
